package com.huawei.mpchartlib.charts;

import com.huawei.mpchartlib.data.LineData;
import com.huawei.mpchartlib.interfaces.dataprovider.LineDataProvider;
import com.huawei.mpchartlib.renderer.LineChartRenderer;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.app.Context;

public class LineChart extends BarLineChartBase<LineData> implements LineDataProvider {

    public LineChart(Context context) {
        super(context);
    }

    public LineChart(Context context, AttrSet attrs) {
        super(context, attrs);
    }

    public LineChart(Context context, AttrSet attrs, String defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void init() {
        super.init();

        mRenderer = new LineChartRenderer(this, null, mViewPortHandler);//mAnimator == null
    }

    @Override
    public LineData getLineData() {
        return mData;
    }

    @Override
    protected void onDetachedFromWindow(Component component) {
        // releases the bitmap in the renderer to avoid oom error
        if (mRenderer != null && mRenderer instanceof LineChartRenderer) {
            ((LineChartRenderer) mRenderer).releasePixelMap();
        }
        super.onDetachedFromWindow(component);
    }
}
